﻿using System;
using System.ComponentModel;

namespace CodeContrib
{
	public static class TypeExtensions
	{
		public static Type GetNullableType(this Type type)
		{
			if (type.IsNullableType())
			{
				var converter = new NullableConverter(type);

				type = converter.UnderlyingType;
			}

			return type;
		}

		public static bool IsNullableType(this Type type)
		{
			return (type.IsGenericType && type.GetGenericTypeDefinition() == typeof (Nullable<>));
		}
	}
}